/********************************************************************
	created:	2010/07/13
	created:	13:7:2010   14:19
	filename: 	D:\Proj\gcstock\code\C++\Base\GCTime.cpp
	file path:	D:\Proj\gcstock\code\C++\Base
	file base:	GCTime
	file ext:	cpp
	author:		Greg Song
	
	purpose:	
*********************************************************************/
#include <time.h>

#include "GCTime.h"
#include "GCArray.h"
#include "GCString.h"

namespace gcstock
{
    GCTimestamp::GCTimestamp():type(24),year(1982),month(3),
        day(26),hour(0),minute(0),second(0)
    {
        
    }
    
    GCTimestamp::GCTimestamp(GCINT t,GCINT y,GCINT mon,GCINT d,GCINT h,GCINT min,GCINT sec):
    type(t),year(y),month(mon),day(d),hour(h),minute(min),second(sec)
    {
        
    }
    
    GCTimestamp::~GCTimestamp()
    {
        
    }
    
    GCTimestamp GCTimestamp::convertToStamp(GCCHAR* strStamp,GCCHAR splitChar)
    {
        GCVArray<GCCHAR*> array;
        splitW(splitChar,strStamp,array);
        
        tm * local;
        time_t t;
        t = time(NULL);
        local = localtime(&t);
        GCINT year = local->tm_year + 1900;
        GCINT month = local->tm_mon + 1;
        GCINT day = local->tm_mday;
        
        GCINT hour = GCSTRTOL(array[0], NULL, 10);
        GCINT minute = GCSTRTOL(array[1], NULL, 10);
        GCINT second = GCSTRTOL(array[2], NULL, 10);
        
        if(hour <= 0 || hour>24)
        {
            
        }
        
        if(minute < 0 || minute>60)
        {
            
        }
        
        if(second < 0 || second > 60)
        {
            
        }
        
        return GCTimestamp(24,year,month,day,hour,minute,second);
    }
    
    GCTestString GCTimestamp::toString()
    {
        //GCTestString str = _GCT("");
        GCSStream str;
        str<<year<<_GCT("/")<<month<<_GCT("/")<<day<<_GCT(" ")<<hour<<_GCT(":")<<minute<<_GCT(":")<<second;
        return str.str();
    }
}